package com.wt.controller;

import com.wt.exception.MyException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import javax.websocket.server.PathParam;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Map;

/**
 * Created with IDEA
 * Describe:
 * Author:tianji
 * Date:2018/9/27
 * Time:11:44
 */
@Controller
public class HelloController {

    @Value("${person.last-name}")
    private String name;
    //日志记录器
    Logger logger = LoggerFactory.getLogger(getClass());

    @RequestMapping("/hello")
    @ResponseBody
    public String sayHello(@RequestParam("user") String user){
        /**
         * 日志级别：由低到高 trace<debug<info<warn<error
         * 可以调整日志的输出级别 日志就会在这个级别以后的高级别发生
         * spring默认使用的是info级别
         */
        logger.trace("这是trace日志.....");
        logger.debug("这是debug日志.....");
        logger.info("我是日志.....");
        logger.warn("这是warn日志....");
        logger.error("这是error日志....");
        if(user.equals("aaa")){
            throw new MyException();
        }
        return "你好，世界"+name;
    }

    @RequestMapping("/success")
    public String successHtml(Map<String,Object> map){
        //classpath:/templates/
        //.html
        map.put("name","张三");
        map.put("id","myDiv01");
        map.put("class","myClass");
        map.put("clubName","<h1>徐汇店</h1>");
        map.put("memberNames", Arrays.asList("张三","李四","王五"));
        return "success";
    }

    @RequestMapping({"/","/index.html"})
    public String index(){
      return "index";
    }
}
